package com.edu.jvm.unit01.stingtable;

/**
 * 测试jdk1.6/1.7/1.8
 * 请永远记住：==比较的是指针(对象首地址)
 *
 * @author five-five
 * @created 2021/10/12-10:30
 */
public class TestStringIntern03 {
    public static void main(String[] args) {
        String s1 = new String("a") + new String("b");
        String s2 = s1.intern();
        System.out.println(s1 == s2);//true
        //1.6:false  1.7/1.8:true
        System.out.println(s1 == "ab");
        //1.6:true  1.7/1.8:true
        System.out.println(s2 == "ab");

        String x = "ab";
        String y = new String("a") + new String("b");
        String z = x.intern();//因为常量池已经有了ab，则不会放入
        System.out.println(z == x);//true
        System.out.println(y == x);//false
        System.out.println(y == z);//false
    }
}
